﻿Public Class LedActivityUserControl
    Implements IRabbitActivityControl
#Region "Events"
    Public Event RemoveLedActivity As EventHandler(Of EventArgs)
#End Region

#Region "Member Fields"
    Private _activity As NabaztagLib.Choreography.LedRabbitActivity
#End Region

#Region "Properties"
    Private Property ActivityImpl() As NabaztagLib.Choreography.IRabbitActivity Implements IRabbitActivityControl.Activity
        Get
            Return Activity
        End Get
        Set(ByVal value As NabaztagLib.Choreography.IRabbitActivity)
            Activity = value
        End Set
    End Property

    Public Property Activity() As NabaztagLib.Choreography.LedRabbitActivity
        Get
            If _activity Is Nothing Then
                _activity = New NabaztagLib.Choreography.LedRabbitActivity
            End If
            Return _activity
        End Get
        Set(ByVal value As NabaztagLib.Choreography.LedRabbitActivity)
            _activity = value
            RebindControls()
        End Set
    End Property
#End Region

#Region "Methods"
    Public Sub RebindControls()
        Select Case Activity.LedLocation
            Case NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.HighLed
                EarComboBox.SelectedItem = "High LED"
            Case NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.LeftLed
                EarComboBox.SelectedItem = "Left LED"
            Case NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.MiddleLed
                EarComboBox.SelectedItem = "Middle LED"
            Case NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.RightLed
                EarComboBox.SelectedItem = "Right LED"
            Case Else
                EarComboBox.SelectedItem = "Bottom LED"
        End Select
        LedColorTextBox.Text = Activity.LedColor.ToString
        ActionMomentNumericUpDown.Value = Activity.ActionMoment
    End Sub
#End Region

#Region "Child Control Event Handlers"
    Private Sub EarComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EarComboBox.SelectedIndexChanged
        Select Case EarComboBox.SelectedItem
            Case "High LED"
                Activity.LedLocation = NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.HighLed
            Case "Left LED"
                Activity.LedLocation = NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.LeftLed
            Case "Middle LED"
                Activity.LedLocation = NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.MiddleLed
            Case "Right LED"
                Activity.LedLocation = NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.RightLed
            Case Else
                Activity.LedLocation = NabaztagLib.Choreography.LedRabbitActivity.LedLocationEnum.BottomLed
        End Select
    End Sub

    Private Sub LedColorButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LedColorButton.Click
        LedColorDialog.SolidColorOnly = True
        If LedColorDialog.ShowDialog = DialogResult.OK Then
            Activity.LedColor = LedColorDialog.Color
            LedColorTextBox.Text = LedColorDialog.Color.ToString
        End If
    End Sub

    Private Sub ActionMomentNumericUpDown_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ActionMomentNumericUpDown.ValueChanged
        Activity.ActionMoment = ActionMomentNumericUpDown.Value
    End Sub

    Private Sub RemoveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RemoveToolStripMenuItem.Click
        RaiseEvent RemoveLedActivity(Me, EventArgs.Empty)
    End Sub
#End Region

End Class
